<template>
  <view class="content">
    <view class="bg fixed-t">
      <image src="/static/image/indexBg.png" mode="aspectFill"/>
    </view>
    <view class="content-box">
      <view class="item" v-for="(item, index) in INDEX_OPTION" :key="index" @click="skip(item)">
        <image :src="item.icon" mode="aspectFill"/>
      </view>
    </view>
  </view>
  <TabBar current-path="/pages/index/index"/>
</template>

<script setup>
import {INDEX_OPTION} from '../../config/base'
import {ref} from "vue";
import {getUserInfo} from '@/api/apiList';
import {onShow} from "@dcloudio/uni-app";

const skip = (item) => {
  if(!userInfo.value.userId) {
	  return  uni.showModal({
	   title: '该功能涉及发布和购买，需要您登录，前往登录页？',
	   icon: 'none',
			success(res) {
				if( res.confirm ) return uni.reLaunch({
				  url: '/subPackage/mine/login'
				})
			}
	 })
  }
  
  if(userInfo.value && userInfo.value.blockDays != 0) {
   return uni.showToast({
     title: '您已被拉黑',
     icon: 'none'
   })
  }
  
  if(userInfo.value && userInfo.value.status  == 2) {
	  return uni.showToast({
	    title: '账号待审核',
	    icon: 'none'
	  })
  }
	// 放行
	uni.navigateTo({
	  url: item.path
	})

}

const userInfo = ref({})
const getUserData = async () => {
  const res = await getUserInfo()
  if (res.code == 200) {
    userInfo.value = res.data;
	uni.setStorageSync('userInfo', res.data)
  }
}

onShow(() => {
	userInfo.value = uni.getStorageSync('userInfo');
	
	if(userInfo.value && userInfo.value.userId){
		getUserData();
	}
})
</script>

<style lang="scss" scoped>
.content {
  .bg {
    image {
      width: 100%;
      height: 1116rpx;
    }
  }
  .content-box {
    padding: 0 30rpx;
    margin-top: 184rpx;
    .item {
      image {
        width: 100%;
        height: 236rpx;
      }
    }
  }

}
</style>
